package cn.qu.phizline.event.common;

import cn.qu.phizline.event.Body;
import cn.qu.phizline.event.Payload;

/**
 * Created by zh on 2017/9/18.
 * <pre>
 *
 * </pre>
 */
public class ResponseEvent extends Payload {
    private static final int TYPE = 1;
    private static final int VERSION = 1;

    @Override
    public int getType() {
        return TYPE;
    }

    @Override
    public int getVersion() {
        return VERSION;
    }

    @Override
    public Class<? extends Body> getBodyType() {
        return ResponseBody.class;
    }

    public static class ResponseBody implements Body {
        private String eventKey;
        private int code;
        private Object data;

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public Object getData() {
            return data;
        }

        public void setData(Object data) {
            this.data = data;
        }

        public String getEventKey() {
            return eventKey;
        }

        public void setEventKey(String eventKey) {
            this.eventKey = eventKey;
        }
    }

    public static ResponseEvent build(String eventKey, int code, Object data) {
        ResponseEvent event = new ResponseEvent();
        ResponseBody body = new ResponseBody();
        body.setEventKey(eventKey);
        body.setData(data);
        body.setCode(code);
        event.setBody(body);
        return event;
    }
}
